package com.lanqiao.javaparkinglot.controller;



import com.lanqiao.javaparkinglot.common.CommonResult;
import com.lanqiao.javaparkinglot.entity.Page;
import com.lanqiao.javaparkinglot.entity.Wliu;
import com.lanqiao.javaparkinglot.service.WliuService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(value ="WliuController" ,tags ="物流修改接口")
@RestController
@RequestMapping("/wliutb")
public class WliuController {
    @Autowired
    WliuService wliuService;
    //查询所有
    @GetMapping("/cha")
    public CommonResult findAll(Wliu wliu){
        List<Wliu> wliuList=wliuService.findAll();
        return CommonResult.success("物流信息表查询数据成功", wliuList);
    }
    //模糊查询负责联系人
    @GetMapping("/findByNumber")
    public Object findByNumber(String word){

        String wordd ="%"+word+"%";
        return wliuService.findByNumber(wordd);
    }
    //模糊查询货物类型
    @GetMapping("/findHws")
    public Object findHws (String word){
        String wordd ="%" + word + "%";
        return wliuService.findHws(wordd);
    }
    //模糊查询车辆类型
    @GetMapping("/findByCar")
    public Object findByCar (String word){
        String wordd="%"+word+"%";
        return wliuService.findByCar(wordd);
    }

    //添加
    @PostMapping("/tianjia")
    public CommonResult addwliu(@RequestBody Wliu wliu){
     wliuService.addwliu(wliu);
      return CommonResult.success("数据添加成功");
    }


    //修改
    @PutMapping("/xiugai")
    public CommonResult updatewliu(@RequestBody Wliu wliu) {
        wliuService.updatewliu(wliu);
        return CommonResult.success("数据修改成功");
    }

    //删除
    @DeleteMapping("/shan/{wl_eno}")
    public CommonResult deletewliu(@PathVariable("wl_eno") Long wl_eno){

        wliuService.deletewliu(wl_eno);
        return CommonResult.success("删除成功");
    }

    //分页查询
    @GetMapping("/fenye")
    public Page<Wliu> fenye(@RequestParam (defaultValue = "1")Integer pageNum,
                            @RequestParam (defaultValue = "17") Integer pageSize){
        Integer offset=(pageNum-1)*10;
        List<Wliu> wliuList= wliuService.findByPage(offset,pageSize);
        Page<Wliu> page=new Page<>();
        page.setData(wliuList);

        Integer pagetotal=wliuService.countWliu();

        page.setPagetotal(pagetotal);
        page.setPageNum(pageNum);
        page.setPageSize(pageSize);
        return  page;


    }
}
